package servlet;

import java.io.IOException;
import java.io.OutputStream;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import pojo.Area;
import service.AreaManage;
import service.impl.AreaManageImpl;

import com.fasterxml.jackson.databind.ObjectMapper;

import dao.AreaDao;
import dao.impl.AreaDaoImpl;
public class SearchServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    public SearchServlet() {
        super();
        
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=utf-8");
		request.setCharacterEncoding("utf-8");
		String name=request.getParameter("keyword");
		AreaManage manage=new AreaManageImpl();
		if(!"".equals(name))
		{
			List<Area> names=manage.findByArea(name);
			ObjectMapper mapper=new ObjectMapper();
			OutputStream outputStream=response.getOutputStream();
			mapper.writeValue(outputStream, names);
			outputStream.close();
		}
		
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
